home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / fsovl / zip / unzip / unzip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-24  |  42.1 KB  |  1,243 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h
  4.  
  5.   This header file is used by all of the unzip source files.  Its contents
  6.   are divided into seven more-or-less separate sections:  predefined macros,
  7.   OS-dependent includes, (mostly) OS-independent defines, typedefs, function 
  8.   prototypes (or "prototypes," in the case of non-ANSI compilers), macros, 
  9.   and global-variable declarations.
  10.  
  11.   ---------------------------------------------------------------------------*/
  12.  
  13. #include "globals.h"
  14.  
  15. /*****************************************/
  16. /*  Predefined, Machine-specific Macros  */
  17. /*****************************************/
  18.  
  19. #if (defined(__GO32__) && defined(unix))   /* DOS extender */
  20. #  undef unix
  21. #endif
  22.  
  23. #if (defined(unix) && !defined(UNIX))
  24. #  define UNIX
  25. #endif /* unix && !UNIX */
  26.  
  27. /* Much of the following is swiped from zip's tailor.h: */
  28.  
  29. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  30. #ifdef __POWERC
  31. #  define __TURBOC__
  32. #  define MSDOS
  33. #endif /* __POWERC */
  34. #if (defined(__TURBOC__) && defined(__MSDOS__) && !defined(MSDOS))
  35. #  define MSDOS
  36. #endif
  37.  
  38. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C,
  39.  * or Silicon Graphics, or Convex, or IBM C Set/2, or GNU gcc under emx, or
  40.  * or Watcom C, or Macintosh, or Windows NT.
  41.  */
  42. #if (__STDC__ || defined(MSDOS) || defined(sgi) || defined(CONVEX))
  43. #  ifndef PROTO
  44. #    define PROTO
  45. #  endif
  46. #  define MODERN
  47. #endif
  48. #if (defined(__IBMC__) || defined(__EMX__) || defined(__WATCOMC__))
  49. #  ifndef PROTO
  50. #    define PROTO
  51. #  endif
  52. #  define MODERN
  53. #endif
  54. #if (defined(THINK_C) || defined(MPW) || defined(WIN32))
  55. #  ifndef PROTO
  56. #    define PROTO
  57. #  endif
  58. #  define MODERN
  59. #endif
  60.  
  61. /* turn off prototypes if requested */
  62. #if (defined(NOPROTO) && defined(PROTO))
  63. #  undef PROTO
  64. #endif
  65.  
  66. /* used to remove arguments in function prototypes for non-ANSI C */
  67. #ifdef PROTO
  68. #  define OF(a) a
  69. #else /* !PROTO */
  70. #  define OF(a) ()
  71. #endif /* ?PROTO */
  72.  
  73. #if (defined(ultrix) || defined(bsd4_2) || defined(sun) || defined(pyr))
  74. #  if (!defined(BSD) && !defined(__SYSTEM_FIVE) && !defined(SYSV))
  75. #    define BSD
  76. #  endif /* !BSD && !__SYSTEM_FIVE && !SYSV */
  77. #endif /* ultrix || bsd4_2 || sun || pyr */
  78.  
  79. #if (defined(CONVEX) || defined(CRAY) || defined(__SYSTEM_FIVE))
  80. #  ifndef TERMIO
  81. #    define TERMIO
  82. #  endif /* !TERMIO */
  83. #endif /* CONVEX || CRAY || __SYSTEM_FIVE */
  84.  
  85. #ifdef pyr  /* Pyramid */
  86. #  ifndef ZMEM
  87. #    define ZMEM
  88. #  endif /* !ZMEM */
  89. #endif /* pyr */
  90.  
  91. #ifdef CRAY
  92. #  ifdef ZMEM
  93. #    undef ZMEM
  94. #  endif /* ZMEM */
  95. #endif /* CRAY */
  96.  
  97. /* the i386 test below is to catch SCO Unix (which has redefinition
  98.  * warnings if param.h is included), but it probably doesn't hurt if
  99.  * other 386 Unixes get nailed, too...except now that 386BSD and BSDI
  100.  * exist.  Sigh.  <sys/param.h> is mostly included for "BSD", I think.
  101.  * [An alternate fix for SCO Unix is below.]
  102.  */
  103. #if (defined(MINIX) || (defined(i386) && defined(unix)))
  104. #  define NO_PARAM_H
  105. #endif /* MINIX || (i386 && unix) */
  106.  
  107.  
  108.  
  109.  
  110.  
  111. /***************************/
  112. /*  OS-Dependent Includes  */
  113. /***************************/
  114.  
  115. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  116. #  include <stdio.h>
  117. #endif
  118. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  119. #include <errno.h>       /* used in mapname() */
  120. #ifndef NO_ERRNO
  121. #  define DECLARE_ERRNO  /* everybody except MSC 6.0, SCO cc, Watcom C/386 */
  122. #endif /* !NO_ERRNO */
  123. #ifdef VMS
  124. #  include <types.h>     /* (placed up here instead of in VMS section below */
  125. #  include <stat.h>      /* because types.h is used in some other headers) */
  126. #else /* !VMS */
  127. #  if !defined(THINK_C) && !defined(MPW)
  128. #    include <sys/types.h>                 /* off_t, time_t, dev_t, ... */
  129. #    include <sys/stat.h>
  130. #  endif /* !THINK_C && !MPW */
  131. #endif /* ?VMS */
  132.  
  133. #ifdef MODERN
  134. #  if (!defined(M_XENIX) && !(defined(__GNUC__) && defined(sun)))
  135. #    include <stddef.h>
  136. #  endif
  137. #  if (!defined(__GNUC__) && !defined(apollo))   /* both define __STDC__ */
  138. #    include <stdlib.h>    /* standard library prototypes, malloc(), etc. */
  139. #  else
  140. #    ifdef __EMX__
  141. #      include <stdlib.h>  /* emx IS gcc but has stdlib.h */
  142. #    endif
  143. #  endif
  144. #  include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  145.    typedef size_t extent;
  146.    typedef void voidp;
  147. #else /* !MODERN */
  148.    char *malloc();
  149.    char *strchr(), *strrchr();
  150.    long lseek();
  151.    typedef unsigned int extent;
  152. #  define void int
  153.    typedef char voidp;
  154. #endif /* ?MODERN */
  155.  
  156. /* this include must be down here for SysV.4, for some reason... */
  157. #include <signal.h>      /* used in unzip.c, file_io.c */
  158.  
  159.  
  160.  
  161. /*---------------------------------------------------------------------------
  162.     Next, a word from our Unix (mostly) sponsors:
  163.   ---------------------------------------------------------------------------*/
  164.  
  165. #ifdef UNIX
  166. #  ifdef AMIGA
  167. #    include <libraries/dos.h>
  168. #  else /* !AMIGA */
  169. #    ifndef NO_PARAM_H
  170. #if 0  /* [GRR: this is an alternate fix for SCO's redefinition bug] */
  171. #      ifdef NGROUPS_MAX
  172. #        undef NGROUPS_MAX     /* SCO bug:  defined again in <param.h> */
  173. #      endif /* NGROUPS_MAX */
  174. #endif /* 0 */
  175. #      include <sys/param.h>   /* conflict with <sys/types.h>, some systems? */
  176. #    endif /* !NO_PARAM_H */
  177. #  endif /* ?AMIGA */
  178.  
  179. #  ifndef BSIZE
  180. #    ifdef MINIX
  181. #      define BSIZE   1024
  182. #    else /* !MINIX */
  183. #      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
  184. #    endif /* ?MINIX */
  185. #  endif
  186.  
  187. #  ifndef BSD
  188. #    if (!defined(AMIGA) && !defined(MINIX))
  189. #      define NO_MKDIR           /* for mapname() */
  190. #    endif /* !AMIGA && !MINIX */
  191. #    include <time.h>
  192. #  else   /* BSD */
  193. #    include <sys/time.h>
  194. #    include <sys/timeb.h>
  195. #    ifdef _AIX
  196. #      include <time.h>
  197. #    endif
  198. #  endif
  199.  
  200. #else   /* !UNIX */
  201. #  define BSIZE   512               /* disk block size */
  202. #endif /* ?UNIX */
  203.  
  204. #if (defined(V7) || defined(BSD))
  205. #  define strchr    index
  206. #  define strrchr   rindex
  207. #endif
  208.  
  209. /*---------------------------------------------------------------------------
  210.     And now, our MS-DOS and OS/2 corner:
  211.   ---------------------------------------------------------------------------*/
  212.  
  213. #ifdef __TURBOC__
  214. #  define DOS_OS2
  215. #  include <sys/timeb.h>      /* for structure ftime                        */
  216. #  ifndef __BORLANDC__        /* there appears to be a bug (?) in Borland's */
  217. #    include <mem.h>          /*   MEM.H related to __STDC__ and far poin-  */
  218. #  endif                      /*   ters. (dpk)  [mem.h included for memcpy] */
  219. #  include <dos.h>            /* for REGS macro (at least for Turbo C 2.0)  */
  220. #else                         /* NOT Turbo C (or Power C)...                */
  221. #  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
  222. #    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
  223. #      define MSC             /*   necessary (it is in 5.0; apparently not  */
  224. #    endif                    /*   in 5.1 and 6.0)                          */
  225. #    include <dos.h>          /* for _dos_setftime()                        */
  226. #  endif
  227. #endif
  228.  
  229. #if (defined(__IBMC__) && defined(__OS2__))
  230. #  define DOS_OS2
  231. #  define S_IFMT 0xF000
  232. #  define timezone _timezone
  233. #endif
  234.  
  235. #ifdef __WATCOMC__
  236. #  define DOS_OS2
  237. #  define __32BIT__
  238. #  ifdef DECLARE_ERRNO
  239. #    undef DECLARE_ERRNO
  240. #  endif
  241. #  undef far
  242. #  define far
  243. #endif
  244.  
  245. #ifdef __EMX__
  246. #  define DOS_OS2
  247. #  define __32BIT__
  248. #  define far
  249. #endif /* __EMX__ */
  250.  
  251. #ifdef MSC                    /* defined for all versions of MSC now         */
  252. #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
  253. #  if (defined(_MSC_VER) && (_MSC_VER >= 600))    /* new with 5.1 or 6.0 ... */
  254. #    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
  255. #  endif                      /*   library (or something)--incompatible with */
  256. #endif                        /*   the usual "extern int errno" declaration  */
  257.  
  258. #ifdef DOS_OS2                /* defined for all MS-DOS and OS/2 compilers   */
  259. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  260. #  include <time.h>           /* localtime() */
  261. #endif
  262.  
  263. #ifdef OS2                    /* defined for all OS/2 compilers */
  264. #  ifdef isupper
  265. #    undef isupper
  266. #  endif
  267. #  ifdef tolower
  268. #    undef tolower
  269. #  endif
  270. #  define isupper(x)   IsUpperNLS((unsigned char)(x))
  271. #  define tolower(x)   ToLowerNLS((unsigned char)(x))
  272. #endif
  273.  
  274. #ifdef WIN32
  275. #  include <io.h>             /* read(), open(), etc. */
  276. #  include <time.h>
  277. #  include <memory.h>
  278. #  include <direct.h>         /* mkdir() */
  279. #  ifdef FILE_IO_C
  280. #    include <fcntl.h>
  281. #    include <conio.h>
  282. #    include <sys\types.h>
  283. #    include <sys\utime.h>
  284. #    include <windows.h>
  285. #    define DOS_OS2
  286. #    define getch() getchar()
  287. #  endif
  288. #endif
  289.  
  290. /*---------------------------------------------------------------------------
  291.     Followed by some VMS (mostly) stuff:
  292.   ---------------------------------------------------------------------------*/
  293.  
  294. #ifdef VMS
  295. #  include <time.h>               /* the usual non-BSD time functions */
  296. #  include <file.h>               /* same things as fcntl.h has */
  297. #  include <rms.h>
  298. #  define _MAX_PATH NAM$C_MAXRSS  /* to define FILNAMSIZ below */
  299. #  define UNIX                    /* can share most of same code from now on */
  300. #  define RETURN    return_VMS    /* VMS interprets return codes incorrectly */
  301. #else /* !VMS */
  302. #  ifndef THINK_C
  303. #    define RETURN  return        /* only used in main() */
  304. #  else
  305. #    define RETURN(v) { int n;\
  306.                         n = (v);\
  307.                         fprintf(stderr, "\npress <return> to continue ");\
  308.                         while (getc(stdin) != '\n');\
  309.                         putc('\n', stderr);\
  310.                         InitCursor();\
  311.                         goto start;\
  312.                       }
  313. #  endif
  314. #  ifdef V7
  315. #    define O_RDONLY  0
  316. #    define O_WRONLY  1
  317. #    define O_RDWR    2
  318. #  else /* !V7 */
  319. #    ifdef MTS
  320. #      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  321. #      include <timeb.h>
  322. #      include <time.h>
  323. #    else /* !MTS */
  324. #      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
  325. #        include <sys/fcntl.h>
  326. #        define SHORT_NAMES
  327. #        define tzset  settz
  328. #      else /* !COHERENT */
  329. #        include <fcntl.h>      /* O_BINARY for open() w/o CR/LF translation */
  330. #      endif /* ?COHERENT */
  331. #    endif /* ?MTS */
  332. #  endif /* ?V7 */
  333. #endif /* ?VMS */
  334.  
  335. #if (defined(MSDOS) || defined(VMS))
  336. #  define DOS_VMS
  337. #endif
  338.  
  339. /*---------------------------------------------------------------------------
  340.     And some Mac stuff for good measure:
  341.   ---------------------------------------------------------------------------*/
  342.  
  343. #ifdef THINK_C
  344. #  define MACOS
  345. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  346. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  347. #  else /* __STDC__ defined */
  348. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  349. #      undef __STDC__         /*   it needs to be 1 or required header */
  350. #      define __STDC__ 1      /*   files are not properly included. */
  351. #    endif /* !__STDC__ */
  352. #  endif /* ?defined(__STDC__) */
  353. #endif /* THINK_C */
  354.  
  355. #ifdef MPW
  356. #  define MACOS
  357. #  include <Errors.h>
  358. #  include <Files.h>
  359. #  include <Memory.h>
  360. #  include <Quickdraw.h>
  361. #  include <ToolUtils.h>
  362. #  define CtoPstr c2pstr
  363. #  define PtoCstr p2cstr
  364. #  ifdef CR
  365. #    undef  CR
  366. #  endif
  367. #endif /* MPW */
  368.  
  369. #ifdef MACOS
  370. #  define open(x,y) macopen(x,y, gnVRefNum, glDirID)
  371. #  define close macclose
  372. #  define read macread
  373. #  define write macwrite
  374. #  define lseek maclseek
  375. #  define creat(x,y) maccreat(x, gnVRefNum, glDirID, gostCreator, gostType)
  376. #  define stat(x,y) macstat(x,y,gnVRefNum, glDirID)
  377.  
  378. #  ifndef isascii
  379. #    define isascii(c) ((unsigned char)(c) <= 0x3F)
  380. #  endif
  381.  
  382. #  include "macstat.h"
  383.  
  384. typedef struct _ZipExtraHdr {
  385.     unsigned short header;    /*    2 bytes */
  386.     unsigned short data;      /*    2 bytes */
  387. } ZIP_EXTRA_HEADER;
  388.  
  389. typedef struct _MacInfoMin {
  390.     unsigned short header;    /*    2 bytes */
  391.     unsigned short data;      /*    2 bytes */
  392.     unsigned long signature;  /*    4 bytes */
  393.     FInfo finfo;              /*   16 bytes */
  394.     unsigned long lCrDat;     /*    4 bytes */
  395.     unsigned long lMdDat;     /*    4 bytes */
  396.     unsigned long flags ;     /*    4 bytes */
  397.     unsigned long lDirID;     /*    4 bytes */
  398.                               /*------------*/
  399. } MACINFOMIN;                 /* = 40 bytes for size of data */
  400.  
  401. typedef struct _MacInfo {
  402.     unsigned short header;    /*    2 bytes */
  403.     unsigned short data;      /*    2 bytes */
  404.     unsigned long signature;  /*    4 bytes */
  405.     FInfo finfo;              /*   16 bytes */
  406.     unsigned long lCrDat;     /*    4 bytes */
  407.     unsigned long lMdDat;     /*    4 bytes */
  408.     unsigned long flags ;     /*    4 bytes */
  409.     unsigned long lDirID;     /*    4 bytes */
  410.     char rguchVolName[28];    /*   28 bytes */
  411.                               /*------------*/
  412. } MACINFO;                    /* = 68 bytes for size of data */
  413. #endif /* MACOS */
  414.  
  415. /*---------------------------------------------------------------------------
  416.     And finally, some random extra stuff:
  417.   ---------------------------------------------------------------------------*/
  418.  
  419. #ifdef MINIX
  420. #  include <stdio.h>
  421. #endif
  422.  
  423. #ifdef SHORT_NAMES         /* Mark Williams C, ...? */
  424. #  define extract_or_test_files    xtr_or_tst_files
  425. #  define extract_or_test_member   xtr_or_tst_member
  426. #endif
  427.  
  428. #ifdef MTS
  429. #  include <unix.h>          /* Some important non-ANSI routines */
  430. #  define mkdir(s,n) (-1)    /* No "make directory" capability */
  431. #  define EBCDIC             /* Set EBCDIC conversion on */
  432. #endif
  433.  
  434.  
  435.  
  436.  
  437.  
  438. /*************/
  439. /*  Defines  */
  440. /*************/
  441.  
  442. #define DIR_BLKSIZ    64     /* number of directory entries per block
  443.                               *  (should fit in 4096 bytes, usually) */
  444. #ifndef INBUFSIZ
  445. #  define INBUFSIZ    2048   /* works for MS-DOS small model */
  446. #endif /* !INBUFSIZ */
  447.  
  448. /*
  449.  * If <limits.h> exists on most systems, should include that, since it may
  450.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  451.  * _POSIX_PATH_MAX.
  452.  */
  453. #ifdef DOS_OS2
  454. #  include <limits.h>
  455. #endif /* DOS_OS2 */
  456.  
  457. #ifdef _MAX_PATH
  458. #  define FILNAMSIZ       (_MAX_PATH)
  459. #else /* !_MAX_PATH */
  460. #  define FILNAMSIZ       1025
  461. #endif /* ?_MAX_PATH */
  462.  
  463. #ifndef PATH_MAX
  464. #  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems */
  465. #    define PATH_MAX      MAXPATHLEN
  466. #  else
  467. #    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
  468. #      define PATH_MAX    FILENAME_MAX
  469. #    else
  470. #      define PATH_MAX    (FILNAMSIZ - 1)
  471. #    endif
  472. #  endif /* ?MAXPATHLEN */
  473. #endif /* !PATH_MAX */
  474.  
  475. #define OUTBUFSIZ         INBUFSIZ
  476.  
  477. #define ZSUFX             ".zip"
  478. #define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  479. #define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
  480. #define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for */
  481. #define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
  482.  
  483. #define SKIP              0    /* choice of activities for do_string() */
  484. #define DISPLAY           1
  485. #define FILENAME          2
  486. #define EXTRA_FIELD       3
  487.  
  488. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  489. #define EXISTS_AND_OLDER  0
  490. #define EXISTS_AND_NEWER  1
  491.  
  492. #define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
  493. #define AMIGA_            1
  494. #define VMS_              2    /* make sure these are not defined on */
  495. #define UNIX_             3    /*  the respective systems!!  (like, for */
  496. #define VM_CMS_           4    /*  instance, "VMS", or "UNIX":  CFLAGS = */
  497. #define ATARI_            5    /*  -O -DUNIX) */
  498. #define OS2_HPFS_         6
  499. #define MAC_              7
  500. #define Z_SYSTEM_         8
  501. #define CPM_              9
  502. /* #define TOPS20_   10?  (TOPS20_ is to be defined in PKZIP 2.0...)  */
  503. #define NUM_HOSTS         10   /* index of last system + 1 */
  504.  
  505. #define STORED            0    /* compression methods */
  506. #define SHRUNK            1
  507. #define REDUCED1          2
  508. #define REDUCED2          3
  509. #define REDUCED3          4
  510. #define REDUCED4          5
  511. #define IMPLODED          6
  512. #define TOKENIZED         7
  513. #define DEFLATED          8
  514. #define NUM_METHODS       9    /* index of last method + 1 */
  515. /* don't forget to update list_files() appropriately if NUM_METHODS changes */
  516.  
  517. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  518. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  519. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  520.  
  521. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  522. #define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
  523.  
  524. /*---------------------------------------------------------------------------
  525.     True sizes of the various headers, as defined by PKWare--so it is not
  526.     likely that these will ever change.  But if they do, make sure both these
  527.     defines AND the typedefs below get updated accordingly.
  528.   ---------------------------------------------------------------------------*/
  529. #define LREC_SIZE     26    /* lengths of local file headers, central */
  530. #define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  531. #define ECREC_SIZE    18    /*  central-dir record, respectively      */
  532.  
  533. #ifdef NOTDEF
  534. #define MAX_BITS      13                 /* used in unShrink() */
  535. #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  536. #endif
  537.  
  538. #define LF      10    /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
  539. #define CR      13    /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
  540. #define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
  541.  
  542. #ifdef EBCDIC
  543. #  define ascii_to_native(c)   ebcdic[(c)]
  544. #  define NATIVE    "EBCDIC"
  545. #endif
  546.  
  547. #if MPW
  548. #  define FFLUSH    putc('\n',stderr);
  549. #else /* !MPW */
  550. #  define FFLUSH    fflush(stderr);
  551. #endif /* ?MPW */
  552.  
  553. #ifdef VMS
  554. #  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
  555. #  define ENV_ZIPINFO   "ZIPINFO_OPTS"
  556. #else /* !VMS */
  557. #  define ENV_UNZIP     "UNZIP"
  558. #  define ENV_ZIPINFO   "ZIPINFO"
  559. #endif /* ?VMS */
  560.  
  561. #ifdef CRYPT
  562. #  define PWLEN         80
  563. #  define DECRYPT(b)    (update_keys(t=((b)&0xff)^decrypt_byte()),t)
  564. #endif /* CRYPT */
  565.  
  566. #ifdef QQ  /* Newtware version */
  567. #  define QCOND   (!quietflg)   /* for no file comments with -vq or -vqq */
  568. #else      /* (original) Bill Davidsen version  */
  569. #  define QCOND   (which_hdr)   /* no way to kill file comments with -v, -l */
  570. #endif
  571.  
  572. #ifndef TRUE
  573. #  define TRUE      1   /* sort of obvious */
  574. #endif
  575. #ifndef FALSE
  576. #  define FALSE     0
  577. #endif
  578.  
  579. #ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
  580. #  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
  581. #  define SEEK_CUR  1
  582. #  define SEEK_END  2
  583. #endif
  584.  
  585. #ifndef S_IRUSR
  586. #  define S_IRWXU       00700       /* read, write, execute: owner */
  587. #  define S_IRUSR       00400       /* read permission: owner */
  588. #  define S_IWUSR       00200       /* write permission: owner */
  589. #  define S_IXUSR       00100       /* execute permission: owner */
  590. #  define S_IRWXG       00070       /* read, write, execute: group */
  591. #  define S_IRGRP       00040       /* read permission: group */
  592. #  define S_IWGRP       00020       /* write permission: group */
  593. #  define S_IXGRP       00010       /* execute permission: group */
  594. #  define S_IRWXO       00007       /* read, write, execute: other */
  595. #  define S_IROTH       00004       /* read permission: other */
  596. #  define S_IWOTH       00002       /* write permission: other */
  597. #  define S_IXOTH       00001       /* execute permission: other */
  598. #endif /* !S_IRUSR */
  599.  
  600. #ifdef ZIPINFO      /* these are individually checked because SysV doesn't */
  601. #  ifndef S_IFBLK   /*  have some of them, Microsoft C others, etc. */
  602. #    define   S_IFBLK     0060000     /* block special */
  603. #  endif
  604. #  ifndef S_IFIFO  /* in Borland C, not MSC */
  605. #    define   S_IFIFO     0010000     /* fifo */
  606. #  endif
  607. #  ifndef S_IFLNK  /* in BSD, not SysV */
  608. #    define   S_IFLNK     0120000     /* symbolic link */
  609. #  endif
  610. #  ifndef S_IFSOCK  /* in BSD, not SysV */
  611. #    define   S_IFSOCK    0140000     /* socket */
  612. #  endif
  613. #  ifndef S_ISUID
  614. #    define S_ISUID       04000       /* set user id on execution */
  615. #  endif
  616. #  ifndef S_ISGID
  617. #    define S_ISGID       02000       /* set group id on execution */
  618. #  endif
  619. #  ifndef S_ISVTX
  620. #    define S_ISVTX       01000       /* directory permissions control */
  621. #  endif
  622. #  ifndef S_ENFMT
  623. #    define S_ENFMT       S_ISGID     /* record locking enforcement flag */
  624. #  endif
  625. #endif /* ZIPINFO */
  626.  
  627.  
  628.  
  629.  
  630.  
  631. /**************/
  632. /*  Typedefs  */
  633. /**************/
  634.  
  635. #ifdef NOTDEF
  636. #ifndef _BULL_SOURCE                /* Bull has it defined somewhere already */
  637.    typedef unsigned char  byte;     /* code assumes UNSIGNED bytes */
  638. #endif /* !_BULL_SOURCE */
  639. #endif
  640.  
  641. typedef char              boolean;
  642. typedef long              longint;
  643. #ifndef EXEC_TYPES_H
  644. typedef unsigned short    UWORD;
  645. typedef unsigned long     ULONG;
  646. #endif
  647.  
  648. typedef struct min_info {
  649.     unsigned unix_attr;
  650.     unsigned dos_attr;
  651.     int hostnum;
  652.     longint offset;
  653.     ULONG compr_size;        /* compressed size (needed if extended header) */
  654.     ULONG crc;               /* crc (needed if extended header) */
  655.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  656.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  657.     unsigned text : 1;       /* file is text or binary */
  658.     unsigned lcflag : 1;     /* convert filename to lowercase */
  659. } min_info;
  660.  
  661. typedef struct VMStimbuf {
  662.     char *revdate;           /* (both correspond to Unix modtime/st_mtime) */
  663.     char *credate;
  664. } VMStimbuf;
  665.  
  666. /*---------------------------------------------------------------------------
  667.     Zipfile layout declarations.  If these headers ever change, make sure the
  668.     xxREC_SIZE defines (above) change with them!
  669.   ---------------------------------------------------------------------------*/
  670.  
  671.    typedef byte   local_byte_hdr[ LREC_SIZE ];
  672. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  673. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  674. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  675. #      define L_COMPRESSION_METHOD              4
  676. #      define L_LAST_MOD_FILE_TIME              6
  677. #      define L_LAST_MOD_FILE_DATE              8
  678. #      define L_CRC32                           10
  679. #      define L_COMPRESSED_SIZE                 14
  680. #      define L_UNCOMPRESSED_SIZE               18
  681. #      define L_FILENAME_LENGTH                 22
  682. #      define L_EXTRA_FIELD_LENGTH              24
  683.  
  684.    typedef byte   cdir_byte_hdr[ CREC_SIZE ];
  685. #      define C_VERSION_MADE_BY_0               0
  686. #      define C_VERSION_MADE_BY_1               1
  687. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  688. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  689. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  690. #      define C_COMPRESSION_METHOD              6
  691. #      define C_LAST_MOD_FILE_TIME              8
  692. #      define C_LAST_MOD_FILE_DATE              10
  693. #      define C_CRC32                           12
  694. #      define C_COMPRESSED_SIZE                 16
  695. #      define C_UNCOMPRESSED_SIZE               20
  696. #      define C_FILENAME_LENGTH                 24
  697. #      define C_EXTRA_FIELD_LENGTH              26
  698. #      define C_FILE_COMMENT_LENGTH             28
  699. #      define C_DISK_NUMBER_START               30
  700. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  701. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  702. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  703.  
  704.    typedef byte   ec_byte_rec[ ECREC_SIZE+4 ];
  705. /*     define SIGNATURE                         0   space-holder only */
  706. #      define NUMBER_THIS_DISK                  4
  707. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  708. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  709. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  710. #      define SIZE_CENTRAL_DIRECTORY            12
  711. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  712. #      define ZIPFILE_COMMENT_LENGTH            20
  713.  
  714.  
  715.    typedef struct local_file_header {                 /* LOCAL */
  716.        byte version_needed_to_extract[2];
  717.        UWORD general_purpose_bit_flag;
  718.        UWORD compression_method;
  719.        UWORD last_mod_file_time;
  720.        UWORD last_mod_file_date;
  721.        ULONG crc32;
  722.        ULONG compressed_size;
  723.        ULONG uncompressed_size;
  724.        UWORD filename_length;
  725.        UWORD extra_field_length;
  726.    } local_file_hdr;
  727.  
  728.    typedef struct central_directory_file_header {     /* CENTRAL */
  729.        byte version_made_by[2];
  730.        byte version_needed_to_extract[2];
  731.        UWORD general_purpose_bit_flag;
  732.        UWORD compression_method;
  733.        UWORD last_mod_file_time;
  734.        UWORD last_mod_file_date;
  735.        ULONG crc32;
  736.        ULONG compressed_size;
  737.        ULONG uncompressed_size;
  738.        UWORD filename_length;
  739.        UWORD extra_field_length;
  740.        UWORD file_comment_length;
  741.        UWORD disk_number_start;
  742.        UWORD internal_file_attributes;
  743.        ULONG external_file_attributes;
  744.        ULONG relative_offset_local_header;
  745.    } cdir_file_hdr;
  746.  
  747.    typedef struct end_central_dir_record {            /* END CENTRAL */
  748.        UWORD number_this_disk;
  749.        UWORD num_disk_with_start_central_dir;
  750.        UWORD num_entries_centrl_dir_ths_disk;
  751.        UWORD total_entries_central_dir;
  752.        ULONG size_central_directory;
  753.        ULONG offset_start_central_directory;
  754.        UWORD zipfile_comment_length;
  755.    } ecdir_rec;
  756.  
  757.  
  758.  
  759.  
  760.  
  761. /*************************/
  762. /*  Function Prototypes  */
  763. /*************************/
  764.  
  765. #ifndef __
  766. #  define __(x) x
  767. #endif
  768.  
  769. /*---------------------------------------------------------------------------
  770.     Functions in unzip.c and/or zipinfo.c:
  771.   ---------------------------------------------------------------------------*/
  772.  
  773. int    usage                     __((int error));
  774. int    process_zipfile           __((void));
  775. int    find_end_central_dir      __((void));
  776. int    process_end_central_dir   __((void));
  777. int    list_files                __((void));                      /* unzip.c */
  778. int    process_cdir_file_hdr     __((void));                      /* unzip.c */
  779. int    process_local_file_hdr    __((void));                      /* unzip.c */
  780. int    process_central_dir       __((void));
  781. int    long_info                 __((void));                    /* zipinfo.c */
  782. int    short_info                __((void));                    /* zipinfo.c */
  783. char   *zipinfo_time             __((UWORD *datez, UWORD *timez));
  784.  
  785. /*---------------------------------------------------------------------------
  786.     Functions in extract.c:
  787.   ---------------------------------------------------------------------------*/
  788.  
  789. int    extract_or_test_files     __((void));
  790. /* static int   store_info               __((void)); */
  791. /* static int   extract_or_test_member   __((void)); */
  792. int    memextract                __((byte *, ULONG, byte *, ULONG));
  793. int    FlushMemory               __((void));
  794. int    ReadMemoryByte            __((UWORD *x));
  795.  
  796. /*---------------------------------------------------------------------------
  797.     Decompression functions:
  798.   ---------------------------------------------------------------------------*/
  799.  
  800. int    explode                   __((void));                    /* explode.c */
  801.  
  802. void   inflate                   __((void));                    /* inflate.c */
  803.  
  804. void   unReduce                  __((void));                   /* unreduce.c */
  805. /* static void  LoadFollowers    __((void));                    * unreduce.c */
  806.  
  807. void   unShrink                  __((void));                   /* unshrink.c */
  808. /* static void  partial_clear    __((void));                    * unshrink.c */
  809.  
  810. /*---------------------------------------------------------------------------
  811.     Functions in file_io.c and crypt.c:
  812.   ---------------------------------------------------------------------------*/
  813.  
  814. int    open_input_file           __((void));                    /* file_io.c */
  815. int    readbuf                   __((char *buf, register unsigned len));
  816. int    create_output_file        __((void));             /* file_io.c, vms.c */
  817. int    FillBitBuffer             __((void));                    /* file_io.c */
  818. int    ReadByte                  __((UWORD *x));                /* file_io.c */
  819. int    FlushOutput               __((void));             /* file_io.c, vms.c */
  820. /* static int   dos2unix         __((unsigned char *, int));     * file_io.c */
  821. void   set_file_time_and_close   __((void));                    /* file_io.c */
  822. void   handler                   __((int signal));              /* file_io.c */
  823. int    echo                      __((int opt));                 /* file_io.c */
  824. void   echoff                    __((int f));                   /* file_io.c */
  825. void   echon                     __((void));                    /* file_io.c */
  826. char   *getp                     __((char *, char *, int));     /* file_io.c */
  827.  
  828. int    decrypt_byte              __((void));                      /* crypt.c */
  829. void   update_keys               __((int));                       /* crypt.c */
  830. void   init_keys                 __((char *));                    /* crypt.c */
  831.  
  832. /*---------------------------------------------------------------------------
  833.     Macintosh file_io functions:
  834.   ---------------------------------------------------------------------------*/
  835.  
  836. #ifdef MACOS
  837. /* static int   IsHFSDisk        __((int)); */
  838.    void     macfstest            __((int));
  839.    int      macmkdir             __((char *, short, long));
  840.    void     ResolveMacVol        __((short, short *, long *, StringPtr));
  841.    short    macopen              __((char *, short, short, long));
  842.    short    maccreat             __((char *, short, long, OSType, OSType));
  843.    short    macread              __((short, char *, unsigned));
  844.    short    macwrite             __((short, char *, unsigned));
  845.    short    macclose             __((short));
  846.    long     maclseek             __((short, long, short));
  847. #endif
  848.  
  849. /*---------------------------------------------------------------------------
  850.     OS/2 file_io functions:
  851.   ---------------------------------------------------------------------------*/
  852.  
  853. void     ChangeNameForFAT  __((char *name));                   /* os2unzip.c */
  854. int      IsFileNameValid   __((char *name));                   /* os2unzip.c */
  855. int      GetCountryInfo    __((void));                         /* os2unzip.c */
  856. long     GetFileTime       __((char *name));                   /* os2unzip.c */
  857. void     SetPathInfo __((char *path, UWORD moddate, UWORD modtime, int flags));
  858. int      SetLongNameEA     __((char *name, char *longname));   /* os2unzip.c */
  859. int      IsEA              __((void *extra_field));            /* os2unzip.c */
  860. ULONG    SizeOfEAs         __((void *extra_field));            /* os2unzip.c */
  861. void     SetEAs            __((char *path, void *eablock));    /* os2unzip.c */
  862. int      IsUpperNLS        __((int nChr));                     /* os2unzip.c */
  863. int      ToLowerNLS        __((int nChr));                     /* os2unzip.c */
  864.  
  865. /*---------------------------------------------------------------------------
  866.     VMS file_io functions:
  867.   ---------------------------------------------------------------------------*/
  868.  
  869. int      check_format      __((void));                              /* vms.c */
  870. int      find_vms_attrs    __((void));                              /* vms.c */
  871. int      CloseOutputFile   __((void));                              /* vms.c */
  872. /* static byte *extract_block __((struct extra_block *, int *, byte *, int));*/
  873. /* static int  _flush_blocks  __((int final_flag));                  * vms.c */
  874. /* static int  _flush_records __((int final_flag));                  * vms.c */
  875. /* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c */
  876. /* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c */
  877. /* static void message        __((int string, char *status));        * vms.c */
  878.  
  879. int      VMSmunch          __((char *, int, char *));          /* VMSmunch.c */
  880.  
  881. /*---------------------------------------------------------------------------
  882.     Functions in match.c, mapname.c, misc.c, etc.:
  883.   ---------------------------------------------------------------------------*/
  884.  
  885. int      match             __((char *string, char *pattern));     /* match.c */
  886.  
  887. int      mapname           __((int create_dirs));               /* mapname.c */
  888.  
  889. void     UpdateCRC         __((register unsigned char *s, register int len));
  890. int      do_string         __((unsigned int len, int option));     /* misc.c */
  891. time_t   dos_to_unix_time  __((unsigned ddate, unsigned dtime));   /* misc.c */
  892. int      check_for_newer   __((char *filename));                   /* misc.c */
  893. int      dateformat        __((void));                             /* misc.c */
  894. UWORD    makeword          __((byte *b));                          /* misc.c */
  895. ULONG    makelong          __((byte *sig));                        /* misc.c */
  896. void     return_VMS        __((int zip_error));                    /* misc.c */
  897.  
  898. void     envargs           __((int *, char ***, char *));       /* envargs.c */
  899.  
  900. #ifdef AMIGA
  901.    int   utime             __((char *file, time_t timep[]));      /* utime.c */
  902. #endif /* AMIGA */
  903.  
  904. #ifdef ZMEM   /* these MUST be ifdef'd because of conflicts with the std def */
  905.    char  *memset           __((register char *buf, register char init,
  906.                                register unsigned int len));        /* misc.c */
  907.    char  *memcpy           __((register char *dst, register char *src,
  908.                                register unsigned int len));        /* misc.c */
  909. #endif /* ZMEM */
  910.  
  911.  
  912.  
  913.  
  914.  
  915. /************/
  916. /*  Macros  */
  917. /************/
  918.  
  919. #ifndef MAX
  920. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  921. #endif
  922.  
  923. #ifndef MIN
  924. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  925. #endif
  926.  
  927.  
  928. #define LSEEK(abs_offset) {longint request=(abs_offset)+extra_bytes,\
  929.    inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  930.    if(request<0) {fprintf(stderr, SeekMsg, ReportMsg); return(3);}\
  931.    else if(bufstart!=cur_zipfile_bufstart)\
  932.    {cur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
  933.    if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  934.    inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;} else\
  935.    {incnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;}}
  936.  
  937. /*
  938.  *  Seek to the block boundary of the block which includes abs_offset,
  939.  *  then read block into input buffer and set pointers appropriately.
  940.  *  If block is already in the buffer, just set the pointers.  This macro
  941.  *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
  942.  *  A slightly modified version is embedded within extract_or_test_files
  943.  *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  944.  *
  945.  *  macro LSEEK(abs_offset)
  946.  *      ULONG   abs_offset;
  947.  *  {
  948.  *      longint   request = abs_offset + extra_bytes;
  949.  *      longint   inbuf_offset = request % INBUFSIZ;
  950.  *      longint   bufstart = request - inbuf_offset;
  951.  *
  952.  *      if (request < 0) {
  953.  *          fprintf(stderr, SeekMsg, ReportMsg);
  954.  *          return(3);             /-* 3:  severe error in zipfile *-/
  955.  *      } else if (bufstart != cur_zipfile_bufstart) {
  956.  *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  957.  *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  958.  *              return(51);        /-* 51:  unexpected EOF *-/
  959.  *          inptr = inbuf + (int)inbuf_offset;
  960.  *          incnt -= (int)inbuf_offset;
  961.  *      } else {
  962.  *          incnt += (inptr-inbuf) - (int)inbuf_offset;
  963.  *          inptr = inbuf + (int)inbuf_offset;
  964.  *      }
  965.  *  }
  966.  *
  967.  */
  968.  
  969.  
  970. #define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  971.   {error_in_archive=error; if(error>1) return error;}
  972.  
  973. /*
  974.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  975.  *  and unzip.c in several functions.
  976.  *
  977.  *  macro SKIP_(length)
  978.  *      UWORD   length;
  979.  *  {
  980.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  981.  *          error_in_archive = error;   /-* might be warning *-/
  982.  *          if (error > 1)              /-* fatal *-/
  983.  *              return (error);
  984.  *      }
  985.  *  }
  986.  *
  987.  */
  988.  
  989.  
  990. #define OUTB(intc) {*outptr++=(byte)(intc); if (++outcnt==OUTBUFSIZ)\
  991.   FlushOutput();}
  992.  
  993. /*
  994.  *  macro OUTB(intc)
  995.  *  {
  996.  *      *outptr++ = (byte)(intc);
  997.  *      if (++outcnt == OUTBUFSIZ)
  998.  *          FlushOutput();
  999.  *  }
  1000.  *
  1001.  */
  1002.  
  1003.  
  1004. #define READBIT(nbits,zdest) {if(nbits>bits_left) FillBitBuffer();\
  1005.   zdest=(int)((UWORD)bitbuf&mask_bits[nbits]);bitbuf>>=nbits;bits_left-=nbits;}
  1006.  
  1007. /*
  1008.  * macro READBIT(nbits,zdest)
  1009.  *  {
  1010.  *      if (nbits > bits_left)
  1011.  *          FillBitBuffer();
  1012.  *      zdest = (int)((UWORD)bitbuf & mask_bits[nbits]);
  1013.  *      bitbuf >>= nbits;
  1014.  *      bits_left -= nbits;
  1015.  *  }
  1016.  *
  1017.  */
  1018.  
  1019.  
  1020. #define PEEKBIT(nbits) (nbits>bits_left? (FillBitBuffer(),\
  1021.   (UWORD)bitbuf & mask_bits[nbits]) : (UWORD)bitbuf & mask_bits[nbits])
  1022.  
  1023.  
  1024. #define NUKE_CRs(buf,len) {register int i,j; for (i=j=0; j<len;\
  1025.   (buf)[i++]=(buf)[j++]) if ((buf)[j]=='\r') ++j; len=i;}
  1026.  
  1027. /*
  1028.  *  Remove all the ASCII carriage returns from buffer buf (length len),
  1029.  *  shortening as necessary (note that len gets modified in the process,
  1030.  *  so it CANNOT be an expression).  This macro is intended to be used
  1031.  *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  1032.  *  if-test gets performed one time too many, but it doesn't matter.
  1033.  *
  1034.  *  macro NUKE_CRs(buf,len)
  1035.  *  {
  1036.  *      register int   i, j;
  1037.  *
  1038.  *      for (i = j = 0;  j < len;  (buf)[i++] = (buf)[j++])
  1039.  *          if ((buf)[j] == CR)
  1040.  *              ++j;
  1041.  *      len = i;
  1042.  *  }
  1043.  *
  1044.  */
  1045.  
  1046.  
  1047. #define TOLOWER(str1,str2) {char *ps1,*ps2; ps1=(str1)-1; ps2=(str2);\
  1048.   while(*++ps1) *ps2++=(char)(isupper((int)(*ps1))?tolower((int)(*ps1)):*ps1);\
  1049.   *ps2='\0';}
  1050.  
  1051. /*
  1052.  *  Copy the zero-terminated string in str1 into str2, converting any
  1053.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1054.  *  as well, of course.  str1 and str2 may be the same character array.
  1055.  *
  1056.  *  macro TOLOWER( str1, str2 )
  1057.  *  {
  1058.  *      char  *ps1, *ps2;
  1059.  *
  1060.  *      ps1 = (str1) - 1;
  1061.  *      ps2 = (str2);
  1062.  *      while (*++ps1)
  1063.  *          *ps2++ = (char)(isupper((int)(*ps1))? tolower((int)(*ps1)) : *ps1);
  1064.  *      *ps2='\0';
  1065.  *  }
  1066.  *
  1067.  *  NOTES:  This macro makes no assumptions about the characteristics of
  1068.  *    the tolower() function or macro (beyond its existence), nor does it
  1069.  *    make assumptions about the structure of the character set (i.e., it
  1070.  *    should work on EBCDIC machines, too).  The fact that either or both
  1071.  *    of isupper() and tolower() may be macros has been taken into account;
  1072.  *    watch out for "side effects" (in the C sense) when modifying this
  1073.  *    macro.
  1074.  */
  1075.  
  1076.  
  1077. #ifndef ascii_to_native
  1078. #  define ascii_to_native(c)   (c)
  1079. #  define A_TO_N(str1)
  1080. #else
  1081. #  ifndef NATIVE
  1082. #    define NATIVE     "native chars"
  1083. #  endif
  1084. #  define A_TO_N(str1) {register unsigned char *ps1;\
  1085.      for (ps1=str1; *ps1; ps1++) *ps1=ascii_to_native(*ps1);}
  1086. #endif
  1087.  
  1088. /*
  1089.  *  Translate the zero-terminated string in str1 from ASCII to the native
  1090.  *  character set. The translation is performed in-place and uses the
  1091.  *  ascii_to_native macro to translate each character.
  1092.  *
  1093.  *  macro A_TO_N( str1 )
  1094.  *  {
  1095.  *      register unsigned char *ps1;
  1096.  *
  1097.  *      for (ps1 = str1;  *ps1;  ++ps1)
  1098.  *          *ps1 = ascii_to_native(*ps1);
  1099.  *  }
  1100.  *
  1101.  *  NOTE:  Using the ascii_to_native macro means that is it the only part of
  1102.  *    unzip which knows which translation table (if any) is actually in use
  1103.  *    to produce the native character set.  This makes adding new character
  1104.  *    set translation tables easy, insofar as all that is needed is an
  1105.  *    appropriate ascii_to_native macro definition and the translation
  1106.  *    table itself.  Currently, the only non-ASCII native character set
  1107.  *    implemented is EBCDIC, but this may not always be so.
  1108.  */
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114. /*************/
  1115. /*  Globals  */
  1116. /*************/
  1117.  
  1118.    extern int       aflag;
  1119. /* extern int       bflag;   reserved */
  1120.    extern int       cflag;
  1121.    extern int       fflag;
  1122.    extern int       jflag;
  1123.    extern int       overwrite_none;
  1124.    extern int       overwrite_all;
  1125.    extern int       force_flag;
  1126.    extern int       quietflg;
  1127. #ifdef DOS_OS2
  1128.    extern int       sflag;
  1129. #endif
  1130.    extern int       tflag;
  1131.    extern int       uflag;
  1132.    extern int       V_flag;
  1133. #ifdef VMS
  1134.    extern int       secinf;
  1135. #endif
  1136. #ifdef MACOS
  1137.    extern int       hfsflag;
  1138. #endif
  1139.    extern int       process_all_files;
  1140.    extern longint   csize;
  1141.    extern longint   ucsize;
  1142.    extern char      *fnames[];
  1143.    extern char      **fnv;
  1144.    extern char      sig[];
  1145.    extern char      answerbuf[];
  1146.    extern min_info  *pInfo;
  1147.    extern char      *key;
  1148.    extern ULONG     keys[];
  1149.  
  1150. #ifdef NOTDEF
  1151. #ifdef MACOS
  1152.    union work {
  1153.      struct {
  1154.        short *Prefix_of;        /* (8193 * sizeof(short)) */
  1155.        byte *Suffix_of;
  1156.        byte *Stack;
  1157.      } shrink;
  1158.      byte *Slide;
  1159.    };
  1160. #else
  1161.    union work {
  1162.      struct {
  1163.        short Prefix_of[HSIZE + 2];      /* (8194 * sizeof(short)) */
  1164.        byte Suffix_of[HSIZE + 2];       /* also s-f length_nodes (smaller) */
  1165.        byte Stack[HSIZE + 2];           /* also s-f distance_nodes (smaller) */
  1166.      } shrink;
  1167.      byte Slide[WSIZE];
  1168.    };
  1169. #endif
  1170.    extern __far union work area;
  1171.  
  1172. #  define prefix_of area.shrink.Prefix_of
  1173. #  define suffix_of area.shrink.Suffix_of
  1174. #  define stack area.shrink.Stack
  1175. #  define slide area.Slide
  1176.  
  1177. #endif
  1178.  
  1179.    extern ULONG     crc32val;
  1180.    extern UWORD     mask_bits[];
  1181.  
  1182.    extern byte      *inbuf;
  1183.    extern byte      *inptr;
  1184.    extern int       incnt;
  1185.    extern ULONG     bitbuf;
  1186.    extern int       bits_left;
  1187.    extern boolean   zipeof;
  1188.    extern int       zipfd;
  1189. #ifdef MSWIN
  1190.    extern char      *zipfn;
  1191. #else
  1192.    extern char      zipfn[];
  1193. #endif
  1194.    extern longint   extra_bytes;
  1195.    extern longint   cur_zipfile_bufstart;
  1196.    extern byte      *extra_field;
  1197.    extern char      local_hdr_sig[];
  1198.    extern char      central_hdr_sig[];
  1199.    extern char      end_central_sig[];
  1200.    extern local_file_hdr  lrec;
  1201.    extern cdir_file_hdr   crec;
  1202.    extern ecdir_rec       ecrec;
  1203.    extern struct stat     statbuf;
  1204.  
  1205.    extern byte      *outbuf;
  1206.    extern byte      *outptr;
  1207. #ifdef MSWIN
  1208.    extern byte __far *outout;
  1209.    extern char     *filename;
  1210. #else
  1211.    extern byte      *outout;
  1212.    extern char      filename[];
  1213. #endif
  1214.    extern longint   outpos;
  1215.    extern int       outcnt;
  1216.    extern int       outfd;
  1217.    extern int       mem_mode;
  1218.    extern int       disk_full;
  1219.  
  1220.    extern char      *EndSigMsg;
  1221.    extern char      *CentSigMsg;
  1222.    extern char      *SeekMsg;
  1223.    extern char      *ReportMsg;
  1224.  
  1225. #ifdef DECLARE_ERRNO
  1226.    extern int       errno;
  1227. #endif
  1228.  
  1229. #ifdef EBCDIC
  1230.    extern byte      ebcdic[];
  1231. #endif
  1232.  
  1233. #ifdef MACOS
  1234.    extern short     gnVRefNum;
  1235.    extern long      glDirID;
  1236.    extern OSType    gostCreator;
  1237.    extern OSType    gostType;
  1238.    extern boolean   fMacZipped;
  1239.    extern boolean   macflag;
  1240.    extern short     giCursor;
  1241.    extern CursHandle rghCursor[];
  1242. #endif
  1243.